package com.tvunetworks.device.extra.util;


import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author andy
 * @since 2022/4/27
 **/
public class Beanutils {
    /**
     * copy list
     * @param source s
     * @param target t
     * @param <T> t
     * @param <S> s
     * @return list
     */
    public static <T,S> List<T> copyList(List<S> source, Class<T> target){
        List<T> result=new ArrayList<>();
        for (S s : source) {
            T o = null;
            try {
                o = (T) target.newInstance();
            } catch (InstantiationException | IllegalAccessException e) {
                e.printStackTrace();
            }
            assert o != null;
            BeanUtils.copyProperties(s,o);
            result.add(o);
        }
        return result;
    }
}
